package com.dayatang.android.Activity;

import java.util.concurrent.ExecutionException;

import com.dayatang.android.Task.BaseTask;
import com.dayatang.android.config.Config;

import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class FeedbaxkInformationActivity extends BaseActivity {
	
	private EditText fiEditText;
	private String fiString;
	
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.feedback_information_activity);
		
		InitBtn();
	}
	
	private void InitBtn(){
		Button button = (Button) findViewById(R.id.fi_submit_btn);
		button.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				if(checking()){
					SubmitFI();
				}
			}
		});
	}
	
	private void SubmitFI(){
		String url = getServerAddress() + "/remote/feedback-information.action?feedbackContent="+fiString+"&clientType=android&userid="+getUser().getId();
		try {
			String result = new BaseTask(this).execute(url).get();
			if(result.equals(Config.ERROR) || result.equals(Config.SERVERDIE) || result.equals(Config.OTHER) || result == null){
				ManageServerInfo(result);
			} else if(result.equals(Config.OK)){
				ToastShow(getString(R.string.fi_submit_success));
			}
		} catch (InterruptedException e) {
			e.printStackTrace();
		} catch (ExecutionException e) {
			e.printStackTrace();
		}
	}
	
	private boolean checking(){
		fiEditText = (EditText) findViewById(R.id.fi_content);
		fiString = fiEditText.getText().toString();
		if(fiString.equals("")){
			fiEditText.setError(getString(R.string.fi_info_notnull));
			return false;
		}
		return true;
	}
	
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
			this.finish();
			return true;
		}
		return super.onKeyDown(keyCode, event);
	}

}
